package lab02.Test23;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        //2.生日还有几天
        /*
         * 4天=生日日期-当前日期
         * 时间系统单位为毫秒     1000毫秒=1秒4
         *
         * （time1 - time2)/(24*60*60*1000)
         *
         * 日期 ->整数？？？
         *
         * SimpleDateFormat
         * Calendar         日历
         */
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你生日的年份");
        int year = scanner.nextInt();
        System.out.println("请输入你生日的月份");
        int month = scanner.nextInt();
        System.out.println("请输入你生日的天数");
        int day = scanner.nextInt();
        System.out.println("你输入的生日为：" + year + "年" + month + "月" + day + "日");


        //获取现在的时间
        Date nowtime = new Date();
        Date date = new Date(year, month, day);


        //定义现在的时间和生日

        Calendar nowtime2 = Calendar.getInstance();
        nowtime2.setTime(nowtime);


        Calendar birthdaytime = Calendar.getInstance();
        birthdaytime.setTime(date);
        birthdaytime.add(Calendar.YEAR,-1900);
        birthdaytime.add(Calendar.MONTH,-1);
        int nowday = nowtime2.get(Calendar.DAY_OF_YEAR);
        int nowmonth = nowtime2.get(Calendar.MONTH);
        int birthday = birthdaytime.get(Calendar.DAY_OF_YEAR);
        int birthmonth = birthdaytime.get(Calendar.MONTH);
        Calendar birth = Calendar.getInstance();
        int apartday = 0;
        if (birthmonth > nowmonth) {
            apartday = nowday - birthday;
        } else if (birthmonth < nowmonth) {
            apartday = 365 - (nowday - birthday);
        } else {
            if (birthday > nowday) {
                apartday = birthday - nowday;
            } else if (birthday < nowday) {
                apartday = nowday - birthday;
            } else {
                System.out.println("祝你生日快乐！");
            }
        }

        int week = birthdaytime.get(Calendar.DAY_OF_WEEK);


        System.out.println("距离您的生日还有：" + (Math.abs(apartday)-1) + "天");
        System.out.println("你的生日是：星期" + week);
    }
}
